package manager

import (
	"context"
	"fmt"
	"gitcode.com/G-YT/iHealth25/server/global"
	"gitcode.com/G-YT/iHealth25/server/model/common/response"
	"gitcode.com/G-YT/iHealth25/server/model/manager"
	managerReq "gitcode.com/G-YT/iHealth25/server/model/manager/request"
	"gitcode.com/G-YT/iHealth25/server/model/system"
	userReq "gitcode.com/G-YT/iHealth25/server/model/user/request"
	"gitcode.com/G-YT/iHealth25/server/service"
	"gitcode.com/G-YT/iHealth25/server/utils"
	"github.com/gin-gonic/gin"
	"github.com/redis/go-redis/v9"
	"go.uber.org/zap"
	"net/http"
	"strconv"
	"time"
)

type FdHealthManagerApi struct {
}

var fdHealthManagerService = service.ServiceGroupApp.ManagerServiceGroup.FdHealthManagerService
var UserService = service.ServiceGroupApp.UserServiceGroup.UserService

// Register 注册健管师
// @Tags healthManager
// @Summary 注册健管师
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body manager.FdHealthManager true "创建fdHealthManager表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /healthManager/register [post]
func (fdHealthManagerApi *FdHealthManagerApi) Register(c *gin.Context) {
	var fdHealthManager manager.FdHealthManager
	err := c.ShouldBindJSON(&fdHealthManager)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	verify := utils.Rules{
		"Phone":    {utils.NotEmpty()},
		"Password": {utils.NotEmpty()},
		"Name":     {utils.NotEmpty()},
		//"Code":     {utils.NotEmpty()},
		"StoreId": {utils.NotEmpty()},
	}
	if err := utils.Verify(fdHealthManager, verify); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	//key := "Sms:Phone:Code:" + fdHealthManager.Phone
	//captcha, _ := global.GVA_REDIS.Get(context.Background(), key).Result()
	//if captcha != fdHealthManager.Code {
	//	response.Result(200, "", "验证码有误,请核实!", c)
	//	return
	//}
	if err := fdHealthManagerService.CreateFdHealthManager(&fdHealthManager); err != nil {
		global.GVA_LOG.Error(err.Error(), zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithMessage("提交审核成功", c)
	}
}

func (fdHealthManagerApi *FdHealthManagerApi) Login(c *gin.Context) {
	var fdHealthManager manager.FdHealthManager
	err := c.ShouldBindJSON(&fdHealthManager)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if managerInfo, err := fdHealthManagerService.Login(&fdHealthManager); err != nil {
		global.GVA_LOG.Error(err.Error(), zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		fdHealthManagerApi.tokenNextB(c, *managerInfo)
	}
}

func (fdHealthManagerApi *FdHealthManagerApi) tokenNextB(c *gin.Context, managerInfo manager.FdHealthManager) {
	token, claims, err := utils.LoginTokenB(&managerInfo)
	if err != nil {
		global.GVA_LOG.Error("获取token失败!", zap.Error(err))
		response.FailWithMessage("获取token失败", c)
		return
	}
	// 是否多点登陆
	if !global.GVA_CONFIG.System.UseMultipoint {
		utils.SetToken(c, token, int(claims.RegisteredClaims.ExpiresAt.Unix()-time.Now().Unix()))
		response.OkWithDetailed(gin.H{
			"token":    token,
			"userInfo": managerInfo,
		}, "登录成功", c)
		return
	}
	// 获取jwt缓存
	if jwtStr, err := jwtService.GetRedisJWT("HM:SignInToken:" + strconv.FormatUint(uint64(managerInfo.HmId), 10)); err == redis.Nil {
		if err := utils.SetRedisJWT(token, "HM:SignInToken:"+strconv.FormatUint(uint64(managerInfo.HmId), 10)); err != nil {
			global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
			response.FailWithMessage("设置登录状态失败", c)
			return
		}
		utils.SetToken(c, token, int(claims.RegisteredClaims.ExpiresAt.Unix()-time.Now().Unix()))
		response.OkWithDetailed(gin.H{
			"token":    token,
			"userInfo": managerInfo,
		}, "登录成功", c)
	} else if err != nil {
		global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
		response.FailWithMessage("设置登录状态失败", c)
	} else {
		var blackJWT system.JwtBlacklist
		blackJWT.Jwt = jwtStr
		if err := jwtService.JsonInBlacklist(blackJWT); err != nil {
			response.FailWithMessage("jwt作废失败", c)
			return
		}
		if err := utils.SetRedisJWT(token, "HM:SignInToken:"+strconv.FormatUint(uint64(managerInfo.HmId), 10)); err != nil {
			response.FailWithMessage("设置登录状态失败", c)
			return
		}
		utils.SetToken(c, token, int(claims.RegisteredClaims.ExpiresAt.Unix()-time.Now().Unix()))
		response.OkWithDetailed(gin.H{
			"token":    token,
			"userInfo": managerInfo,
		}, "登录成功", c)
	}
}

// DeleteFdHealthManager 删除fdHealthManager表
// @Tags FdHealthManager
// @Summary 删除fdHealthManager表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body manager.FdHealthManager true "删除fdHealthManager表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /fdHealthManager/deleteFdHealthManager [delete]
func (fdHealthManagerApi *FdHealthManagerApi) DeleteFdHealthManager(c *gin.Context) {
	var fdHealthManager manager.FdHealthManager
	err := c.ShouldBindJSON(&fdHealthManager)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdHealthManagerService.DeleteFdHealthManager(fdHealthManager); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteFdHealthManagerByIds 批量删除fdHealthManager表
// @Tags FdHealthManager
// @Summary 批量删除fdHealthManager表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除fdHealthManager表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /fdHealthManager/deleteFdHealthManagerByIds [delete]
func (fdHealthManagerApi *FdHealthManagerApi) DeleteFdHealthManagerByIds(c *gin.Context) {
	var IDS managerReq.IdsHReq
	err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := fdHealthManagerService.DeleteFdHealthManagerByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

func (fdHealthManagerApi *FdHealthManagerApi) UpdateFdHealthManager(c *gin.Context) {
	var fdHealthManager manager.FdHealthManager
	err := c.ShouldBindJSON(&fdHealthManager)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if fdHealthManager.OpenNum != 0 && fdHealthManager.OpenNum > 20 {
		response.FailWithMessage("授权开通会员数不得大于20！", c)
	}
	if err := fdHealthManagerService.UpdateFdHealthManager(fdHealthManager); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// OpenVip 开通会员
func (fdHealthManagerApi *FdHealthManagerApi) OpenVip(c *gin.Context) {
	HmID := utils.GetHmID(c)
	id := c.Query("id")
	vipType := c.Query("vipType")
	authority := utils.GetUserAuthorityId(c)
	if err := fdHealthManagerService.OpenVip(HmID, authority, id, vipType); err != nil {
		global.GVA_LOG.Error("开通失败", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithMessage("开通成功", c)
	}
}

// UpdatePassword 修改密码
// @Tags FdHealthManager
// @Summary 修改密码
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query user.User true "修改密码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /api/fdHealthManager/updatePassword [put]
func (fdHealthManagerApi *FdHealthManagerApi) UpdatePassword(c *gin.Context) {
	var uc userReq.ChangePassword
	err := c.ShouldBindJSON(&uc)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	// 判断两次密码是否相同
	if uc.Password != uc.NewPassword {
		response.FailWithMessage("新密码与确认密码不同", c)
		return
	}
	id := utils.GetHmID(c)
	hmId := strconv.FormatUint(uint64(id), 10)
	userInfo, _ := fdHealthManagerService.GetFdHealthManager(hmId)
	// 判断短信验证码
	key := "Sms:Phone:Code:" + userInfo.Phone
	captcha, _ := global.GVA_REDIS.Get(context.Background(), key).Result()
	if captcha != uc.Code {
		response.Result(200, "", "验证码有误,请核实!", c)
		return
	}
	err = fdHealthManagerService.ChangePassword(id, uc.NewPassword)
	if err != nil {
		global.GVA_LOG.Error("修改失败!", zap.Error(err))
		response.FailWithMessage("修改失败", c)
		return
	}
	response.OkWithMessage("修改成功", c)
}

// ForgetPassword 忘记密码
// @Tags FdHealthManager
// @Summary 忘记密码
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query user.User true "忘记密码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /api/healthManager/forgetPassword [post]
func (fdHealthManagerApi *FdHealthManagerApi) ForgetPassword(c *gin.Context) {
	var uf userReq.ForgetPassword
	err := c.ShouldBindJSON(&uf)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	var info managerReq.FdHealthManagerSearch
	info.Phone = uf.Phone
	healthManager, _ := fdHealthManagerService.FindHealthManagerByWhere(info)
	if healthManager.HmId == 0 {
		response.FailWithMessage("该账号不存在,请注册!", c)
		return
	}
	key := "Sms:Phone:Code:" + uf.Phone
	captcha, _ := global.GVA_REDIS.Get(context.Background(), key).Result()
	if captcha != uf.Code {
		response.FailWithMessage("请输入正确验证码!", c)
		return
	}
	fdHealthManagerApi.tokenNextB(c, healthManager)
	return
}

// FindFdHealthManager 用id查询fdHealthManager表
// @Tags FdHealthManager
// @Summary 用id查询fdHealthManager表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query manager.FdHealthManager true "用id查询fdHealthManager表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /fdHealthManager/findFdHealthManager [get]
func (fdHealthManagerApi *FdHealthManagerApi) FindFdHealthManager(c *gin.Context) {
	hmID := c.Query("hmId")
	if refdHealthManager, err := fdHealthManagerService.GetFdHealthManager(hmID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"refdHealthManager": refdHealthManager}, c)
	}
}

// FindHealthManagerByWhere 根据条件获取健管师
// @Tags FdHealthManager
// @Summary 根据条件获取健管师
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query manager.FdHealthManager true "根据条件获取健管师"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /fdHealthManager/findFdHealthManager [get]
func (fdHealthManagerApi *FdHealthManagerApi) FindHealthManagerByWhere(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if result, err := fdHealthManagerService.FindHealthManagerByWhere(pageInfo); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}

// GetHealthManagersByHmIDs 根据ID集合获取健管师列表【超管】
// @Tags FdHealthManager
// @Summary 根据ID集合获取健管师列表【超管】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query manager.FdHealthManager true "根据ID集合获取健管师列表【超管】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /fdHealthManager/getHealthManagersByHmIDs [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetHealthManagersByHmIDs(c *gin.Context) {
	var pageInfo managerReq.HealthManagerIDs
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := fdHealthManagerService.GetHealthManagersByHmIDs(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetSsHealthManagerList 获取健管师列表【服务站】
// @Tags FdHealthManager
// @Summary 获取健管师列表【服务站】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerSearch true "获取健管师列表【服务站】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fdHealthManager/getFdHealthManagerList [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetSsHealthManagerList(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	// 查询属于当前服务站的健管师
	id := utils.GetUserID(c)
	pageInfo.StoreId = id
	if list, total, err := fdHealthManagerService.GetSsHealthManagerList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetScHealthManagerList 获取全部健管师列表【服务中心】
// @Tags FdHealthManager
// @Summary 获取全部健管师列表【服务中心】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerSearch true "获取全部健管师列表【服务中心】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fdHealthManager/getScHealthManagerList [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetScHealthManagerList(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	// 查询属于当前服务中心的健管师
	ScID := utils.GetUserID(c)
	if list, total, err := fdHealthManagerService.GetScHealthManagerList(pageInfo, ScID); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetAllHealthManagerList 获取全部健管师列表【超管】
// @Tags FdHealthManager
// @Summary 获取全部健管师列表【超管】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerSearch true "获取全部健管师列表【超管】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fdHealthManager/getFdHealthManagerList [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetAllHealthManagerList(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := fdHealthManagerService.GetAllHealthManagerInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetHealthManagerRank 获取健管师排名【超管】
// @Tags FdHealthManager
// @Summary 获取健管师排名【超管】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerSearch true "获取健管师排名【超管】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fdHealthManager/getHealthManagerRank [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetHealthManagerRank(c *gin.Context) {
	var pageInfo managerReq.ManagerRank
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := fdHealthManagerService.GetHealthManagerRank(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetScHealthManagerRank 获取健管师排名【服务中心】
// @Tags FdHealthManager
// @Summary 获取健管师排名【服务中心】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerSearch true "获取健管师排名【服务中心】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fdHealthManager/getScHealthManagerRank [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetScHealthManagerRank(c *gin.Context) {
	var pageInfo managerReq.ManagerRank
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	// 查询属于当前服务中心的健管师
	ScID := utils.GetUserID(c)
	pageInfo.ServiceCentre = ScID
	if list, total, err := fdHealthManagerService.GetScHealthManagerRank(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// ExportExcel 导出健管师Excel【超管】
// @Tags FdHealthManager
// @Summary 导出健管师Excel【超管】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerSearch true "导出健管师Excel【超管】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fdHealthManager/exportExcel [get]
func (fdHealthManagerApi *FdHealthManagerApi) ExportExcel(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	id := utils.GetUserID(c)
	pageInfo.StoreId = id
	if file, name, err := fdHealthManagerService.ExportExcel(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", name+utils.RandomString(6)+".xlsx")) // 对下载的文件重命名
		c.Header("success", "true")
		c.Data(http.StatusOK, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", file.Bytes())
	}
}

// ExportScExcel 导出健管师Excel【服务中心】
// @Tags FdHealthManager
// @Summary 导出健管师Excel【服务中心】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query managerReq.FdHealthManagerSearch true "导出健管师Excel【服务中心】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fdHealthManager/exportScExcel [get]
func (fdHealthManagerApi *FdHealthManagerApi) ExportScExcel(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	ScID := utils.GetUserID(c)
	if file, name, err := fdHealthManagerService.ExportScExcel(pageInfo, ScID); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", name+utils.RandomString(6)+".xlsx")) // 对下载的文件重命名
		c.Header("success", "true")
		c.Data(http.StatusOK, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", file.Bytes())
	}
}

// GetManagerListByPage 分页获取健管师列表【C端用户】
// @Router /steward/getStewardListByPage [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetManagerListByPage(c *gin.Context) {
	var pageInfo managerReq.FdHealthManagerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := fdHealthManagerService.GetStewardListByPage(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetServiceCenterList 获取服务中心列表
// @Router /healthManager/getServiceCenterList [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetServiceCenterList(c *gin.Context) {
	//branchID := c.Query("branchID")
	if list, err := fdHealthManagerService.GetServiceCenterList(); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(list, "获取成功", c)
	}
}

// GetHealthManageCenterList 获取健管中心列表
// @Router /healthManager/getServiceCenterList [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetHealthManageCenterList(c *gin.Context) {
	ID := c.Query("ID")
	if list, err := fdHealthManagerService.GetHealthManageCenterList(ID); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(list, "获取成功", c)
	}
}

// GetPromotionUserList 获取推广用户列表
// @Router /healthManager/getPromotionUserList [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetPromotionUserList(c *gin.Context) {
	var pageInfo userReq.PromotionUserSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	id := utils.GetHmID(c)
	pageInfo.StewardID = id
	if list, err := UserService.GetPromotionUserList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(list, "获取成功", c)
	}
}

// GetHealthManagerInfo 获取健管师个人信息
// @Tags FdHealthManager
// @Summary 获取健管师个人信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query manager.FdHealthManager true "获取健管师个人信息"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /fdHealthManager/getHealthManagerInfo [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetHealthManagerInfo(c *gin.Context) {
	id := utils.GetHmID(c)
	if result, err := fdHealthManagerService.GetHealthManagerInfo(id); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(result, c)
	}
}

// UpdateHealthManagerInfo 编辑健管师个人信息
// @Router /fdHealthManager/updateHealthManagerInfo [post]
func (fdHealthManagerApi *FdHealthManagerApi) UpdateHealthManagerInfo(c *gin.Context) {
	var request manager.FdHealthManager
	err := c.ShouldBindJSON(&request)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	id := utils.GetHmID(c)
	request.HmId = id
	if err := fdHealthManagerService.UpdateFdHealthManagerInfo(request); err != nil {
		global.GVA_LOG.Error("编辑失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithMessage("编辑成功", c)
	}
}

// ApplyAttestation 申请认证
// @Router /fdHealthManager/applyAttestation [get]
func (fdHealthManagerApi *FdHealthManagerApi) ApplyAttestation(c *gin.Context) {
	id := utils.GetHmID(c)
	if err := fdHealthManagerService.ApplyAttestation(id); err != nil {
		global.GVA_LOG.Error("提交申请失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithMessage("提交申请成功", c)
	}
}

// GetAttestationFailReason 认证失败原因
// @Router /fdHealthManager/getAttestationFailReason [get]
func (fdHealthManagerApi *FdHealthManagerApi) GetAttestationFailReason(c *gin.Context) {
	id := utils.GetHmID(c)
	if result, err := fdHealthManagerService.GetAttestationFailReason(id); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithDetailed("", "获取成功", c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}
